<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>连接indexedDB数据库</title>
    <script>
        window.indexedDB = window.indexedDB || window.webkitIndexedDB ||
            window.mozIndexedDB || window.msIndexedDB;
        window.IDBTransaction = window.IDBTransaction ||
            window.webkitIDBTransaction || window.msIDBTransaction;
        window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange ||
            window.msIDBKeyRange;
        window.IDBCursor = window.IDBCursor || window.webkitIDBCursor ||
            window.msIDBCursor;

        function connectDatabase() {
            var dbName = 'indexedDBTest'; //数据库名
            var dbVersion = 20120603;
            var idb;
            var dbConnect = indexedDB.open(dbName, dbVersion);
            dbConnect.onsuccess = function (e) {    //连接成功
                idb = e.target.result;
                alert("连接ok");
            };
            dbConnect.onerror = function () {
                alert('连接失败')
            }
        }
    </script>
</head>
<body>
<input type="button" value="连接数据库" onclick="connectDatabase();">
</body>
</html>